package com.yonyou.pmclouds.reason.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.reason.entity.ProblemReasonVO;
import com.yonyou.pmclouds.reason.rmiimpl.ProblemReasonMaintainImpl;

import static com.yonyou.pmclouds.reason.rmiimpl.ProblemReasonMaintainImpl.*;


public class ProblemReasonInsertRefCheck implements SingleProcessor<ProblemReasonVO> {

    private ProblemReasonMaintainImpl maintain;

    public ProblemReasonInsertRefCheck(ProblemReasonMaintainImpl maintain) {
        this.maintain = maintain;
    }

    @Override
    public void process(ProblemReasonVO vo, ProblemReasonVO orig) throws BusinessException {
        if (vo.getPkParent() == null) {
            return;
        }
        // 引用check
        int status = maintain.getProblemReasonRefStatus(vo.getPkParent(), vo.getPkTenant());
        if (status == STATUS_NOT_REF) {
            return;
        }
        if (status == STATUS_REF_BY_CHILD) {
            return;
        }
        if (status == STATUS_REF_BY_BILL) {
            //存在引用仍然可配修改
            return;

            //throw new BusinessException("父级问题原因已经被引用，不可新增下级！");
        }

    }
}
